#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct data
{
    char name[128]; // 名字
    int age;        // 年龄
} data;

void _relloc_(data *sr, int nead, int real)
{
    if (nead == 0)
    {
        printf("需要的大小为0");
    }
    else if (NULL == sr)
    {
        printf("结构体指针为NULL");
        data *p = (data *)malloc(nead * sizeof(data));
    }
//缩小容量
    else if (real > nead)
    {
        data *p = (data *)malloc(nead * sizeof(data));
        for (size_t i = 0; i < nead; ++i)
            p[i] = sr[i];
        free(sr);
    }
//扩大容量
    else
    {
        data *p = (data *)malloc(nead * sizeof(data));
        for (size_t i = 0; i < real; ++i)
            p[i] = sr[i];
        free(sr);
    }
}
    int main(int argc, char const *argv[])
    {

        data *ptr = (data *)malloc(1000 * sizeof(data));
        for (size_t i = 0; i < 1000; i++)
        {
            strcpy(ptr[i].name, "huzhuo");
            ptr[i].age = i;
        }
        _relloc_(ptr, 50000, 1000); // 函数调用

        return 0;
    }
